use rusqlite::{Connection};
use crate::a1::Item;
fn list_items() ->String {
    let con = Connection::open("data.sqlite").unwrap();
    let sql:&str = "select id,name,bh from parts_item limit 3";
    let mut stmt = con.prepare(sql).unwrap();
    let person_iterator = stmt.query_map([], |row| {
        Ok(Item{
            id: row.get(0).unwrap(),
            name: row.get(1).unwrap(),
            bh: row.get(2).unwrap(),
        })
    }).unwrap();
    // let res=json::stringify(person_iterator);
    let mut res=String::new();
    res.push_str("[");
    for p in person_iterator {
        let p1=p.unwrap();
        res.push_str("{");
        // let s1=json::stringify(p1);
        let s1=format!("bh:{0}",p1.bh);
        println!("{:?}",s1);
        res.push_str(&s1);
        res.push_str("}");
        res.push_str(",");
    }
    res.push_str("]");
    println!("{:?}",res);
    return res;
}
fn test_json(){
    let parsed = json::parse(r#"
    {
        "code": 200,
        "success": true,
        "payload": {
            "features": [
                "awesome",
                "easyAPI",
                "lowLearningCurve"
            ]
        }
    }
    "#).unwrap();

    let instantiated = json::object!{
        "code" => 200,
        "success" => true,
        "payload" => json::object!{
            "features" => json::array![
                "awesome",
                "easyAPI",
                "lowLearningCurve"
            ]
        }
    };

    assert_eq!(parsed, instantiated);
    println!("解析输出字段：code={}",instantiated["code"]);
    println!("解析输出字段：success={}",instantiated["success"]);
    println!("解析输出对象：payload={:?}",instantiated["payload"]);
    println!("解析输出数组：features={:?}",instantiated["payload"]["features"]);
    println!("解析输出数组元素：0={}",instantiated["payload"]["features"][0]);
    println!("解析输出数组元素：1={}",instantiated["payload"]["features"][1]);
    println!("解析输出数组元素：2={}",instantiated["payload"]["features"][2]);
}
pub fn main() {
    list_items();
}
